<?php
namespace app\admin\controller;

use app\common\model\ActionForm as ActionFormModel;

/**
 * 活动表单控制器
 * Class Actionform
 * @package app\index\controller
 */
class Actionform extends Base
{
    /**
     * [find  获取一条]
     * @return mixed|string
     * @author [C。]
     */
    public function find()
    {
        $param = input('param.');
        $model = new ActionFormModel();
        $user = $this->user;
        try{
            $form = $model->findData($param['aid'],'aid','form');
            $form = unserialize($form['form']);
        }catch (\Exception $e) {
            systembug($e->getMessage(),1,'admin/actionform/find');
            return admin_json(-1,'获取失败'.$e->getMessage());
        }
        writelog('查看活动表单', 0,$user);
        return admin_json(1,'获取成功',$form);
    }
    /**
     * [Add  添加]
     * @return mixed|string
     * @author [C。]
     */
    public function add()
    {
        $param = input('param.');
        $model = new ActionFormModel();
        $user = $this->user;
        try{

            $form = $model->findData($param['aid'],'aid');
            $param['form'] = serialize($param['form']);
            if(empty($form)){
                $id = $model->addData($param);
            }else{
                $param['id'] = $form['id'];
                $id = $model->editData($param);
            }
        }catch (\Exception $e) {
            systembug($e->getMessage(),1,'admin/actionform/add');
            return admin_json(-1,'编辑失败'.$e->getMessage());
        }
        writelog('编辑活动表单'.$id, 0,$user);
        return admin_json(1,'编辑成功');
    }
}